package org.chen.wordwave.tools;

import android.content.Context;
import android.content.SharedPreferences;

import java.util.Locale;

public class SharedPreferencesHelper {
    private static final String PREFERENCES_FILE_NAME = "app_preferences";
    private static final String LANGUAGE_KEY = "language";


    public static void setLanguage(Context context, String languageCode) {
        SharedPreferences sharedPreferences = context.getSharedPreferences(PREFERENCES_FILE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(LANGUAGE_KEY, languageCode);
        editor.apply();
    }


    public static String getLanguage(Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences(PREFERENCES_FILE_NAME, Context.MODE_PRIVATE);
        return sharedPreferences.getString(LANGUAGE_KEY, Locale.getDefault().getLanguage());
    }
}
